package bman.filecopy;

import java.io.File;

public class FileSizeTracker extends Thread
{
	File file;
	MessageReceiver mr;
	long size;
	public FileSizeTracker(File f, long s, MessageReceiver r)
	{
		file =f;
		mr = r;
		size = s;
	}
	
	public boolean run = true;
	StringBuffer progress = new StringBuffer();
	public void run()
	{
		while(run)
		{
			try
			{
				if(progress.length() < 7)
				{
					progress.append(".");
				}
				else
				{
					progress.setLength(0);
				}
				
				file = new File(file.getAbsolutePath());
				sleep(500);
				if(file.exists())
				{
					float l = file.length();
					float p = l/(float)size *100;
					//System.out.println("l="+l+", size="+size+", l/size = "+p);
					
					mr.receive("Copying "+file.getName()+" ( "+p+"% ) "+progress.toString());
				}
			}
			catch (Exception e)
			{
				e.printStackTrace();
			}
		}
		mr.receive("Copied "+file.getName()+" ("+file.length()+" bytes)");
	}
}
